<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>学生信息表格</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Microsoft YaHei', sans-serif;
        }
        body {
            background-color: #f5f5f5;
            padding: 40px 20px;
            display: flex;
            flex-direction: column;
            align-items: center;
            min-height: 100vh;
        }
        .container {
            max-width: 800px;
            width: 100%;
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            padding: 20px;
        }
        h1 {
            margin-bottom: 5px;
            color: #333;
        }
        .subtitle {
            margin-bottom: 20px;
            color: #666;
            font-size: 16px;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }
        th {
            background-color: #f0f0f0;
            padding: 12px 15px;
            text-align: left;
            border-bottom: 2px solid #ddd;
            font-weight: 600;
            color: #333;
        }
        td {
            padding: 12px 15px;
            border-bottom: 1px solid #ddd;
            color: #555;
        }
        tbody tr:hover {
            background-color: #f9f9f9;
        }
        .student-list-title {
            font-size: 18px;
            font-weight: 600;
            margin-top: 30px;
            margin-bottom: 10px;
            color: #333;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>学生信息</h1>
        <p class="subtitle">将数组中存储的学生信息，以表格的形式输出到网页中</p>
        <div class="student-list-title">学生列表</div>
        <table>
            <thead>
                <tr>
                    <th>序号</th>
                    <th>姓名</th>
                    <th>年龄</th>
                    <th>性别</th>
                    <th>家乡</th>
                </tr>
            </thead>
            <tbody id="studentTableBody">
            </tbody>
        </table>
    </div>
    <script>
        const students = [
            { id: 1, name: "小明", age: 18, gender: "男", hometown: "河北省" },
            { id: 2, name: "小红", age: 19, gender: "女", hometown: "河南省" },
            { id: 3, name: "小刚", age: 17, gender: "男", hometown: "山西省" },
            { id: 4, name: "小丽", age: 18, gender: "女", hometown: "山东省" }
        ];
        const tableBody = document.getElementById('studentTableBody');
        function renderTable() {
            let tableHTML = '';
            students.forEach(student => {
                tableHTML += `
                    <tr>
                        <td>${student.id}</td>
                        <td>${student.name}</td>
                        <td>${student.age}</td>
                        <td>${student.gender}</td>
                        <td>${student.hometown}</td>
                    </tr>
                `;
            });
            tableBody.innerHTML = tableHTML;
        }
        document.addEventListener('DOMContentLoaded', renderTable);
    </script>
</body>
</html>